package com.aiyige.page.my.message.notifymessage.likemessage.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.my.message.notifymessage.likemessage.model.LikeMessage;
import com.aiyige.page.my.message.util.MessageUtil;
import com.aiyige.utils.DateFormatUtil;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.vondear.rxtools.RxTextTool;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2017/8/14.
 */

public class LikeMessageAdapter extends BaseQuickAdapter<LikeMessage, LikeMessageAdapter.ViewHolder> {


    public LikeMessageAdapter() {
        super(R.layout.like_message_item, new LinkedList<LikeMessage>());
    }

    @Override
    protected void convert(ViewHolder helper, LikeMessage data) {
        helper.bindData(data);
    }

    public static class ViewHolder extends BaseViewHolder {
        @BindView(R.id.otherHeadIv)
        ImageView otherHeadIv;
        @BindView(R.id.otherNameTv)
        TextView otherNameTv;
        @BindView(R.id.otherTimeTv)
        TextView otherTimeTv;
        @BindView(R.id.otherLikeMessageTv)
        TextView otherLikeMessageTv;
        @BindView(R.id.myCommentTv)
        TextView myCommentTv;
        @BindView(R.id.coverIv)
        ImageView coverIv;
        @BindView(R.id.mediaReleaseDateTv)
        TextView mediaReleaseDateTv;
        @BindView(R.id.mediaTitleTv)
        TextView mediaTitleTv;
        @BindView(R.id.playIv)
        ImageView playIv;
        @BindView(R.id.myLayout)
        View myLayout;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            addOnClickListener(R.id.otherHeadIv);
            addOnClickListener(R.id.otherNameTv);
        }

        public void bindData(LikeMessage data) {
            otherNameTv.setText(data.getOtherName());
            Glide.with(itemView.getContext())
                    .load(data.getOtherAvatar())
                    .apply(RequestOptions.placeholderOf(R.drawable.default_head))
                    .apply(RequestOptions.circleCropTransform())
                    .into(otherHeadIv);

            Glide.with(itemView.getContext())
                    .load(data.getCover())
                    .apply(RequestOptions.placeholderOf(R.drawable.default_image_bg))
                    .into(coverIv);

            otherTimeTv.setText(DateFormatUtil.getStandardDate(data.getOtherTime()));
            mediaTitleTv.setText(data.getMediaTitle());
            mediaReleaseDateTv.setText(DateFormatUtil.formatMS("yyyy-MM-dd", data.getMediaReleaseDate()));
            playIv.setVisibility(data.getTargetType() == MessageUtil.TARGET_TYPE_VIDEO || data.getTargetType() == MessageUtil.TARGET_TYPE_LEARN_VIDEO? View.VISIBLE : View.INVISIBLE);
            switch (data.getTargetType()) {
                case MessageUtil.TARGET_TYPE_COMMENT:
                    myLayout.setVisibility(View.VISIBLE);
                    RxTextTool.getBuilder("")
                            .append(data.getMyName() + ": ").setForegroundColor(0xff909090).setProportion(1.1f)
                            .append(data.getMyComment()).setForegroundColor(0xff606060)
                            .into(myCommentTv);
                    otherLikeMessageTv.setText(R.string.other_like_comment_message);
                    break;
                default:
                    myLayout.setVisibility(View.GONE);
                    otherLikeMessageTv.setText(R.string.other_like_media_message);
                    break;
            }

        }
    }
}
